EXEC msdb.dbo.sp_send_dbmail
    @profile_name = 'AdventureWorks Administrator',
    @recipients = 'danw@Adventure-Works.com',
    @body = 'The stored procedure finished successfully.',
    @subject = 'Automated Success Message' ;

EXECUTE msdb.dbo.sysmail_delete_log_sp
    @logged_before = 'November 3, 2013' ;
go

EXec msdb.dbo.sp_notify_operator @name=N'Yong Choi',@body=N'Reorgnizationg of Indexes are failed', @profile_name='default'
go

dbo.sysmail_start_sp
USE Master
GO
sp_configure 'show advanced options', 1
GO
reconfigure with override
GO
sp_configure 'Database Mail XPs', 1
GO
reconfigure 
GO
sp_configure 'show advanced options', 0
GO


EXECUTE msdb.dbo.sysmail_add_profile_sp
@profile_name = 'DoNotReply',
@description = 'Profile to send the notification emails'
GO



EXECUTE msdb.dbo.sysmail_add_principalprofile_sp
@profile_name = 'DoNotReply',
@principal_name = 'public',
@is_default = 1 ; -- Make this the default profile
GO


EXECUTE msdb.dbo.sysmail_add_account_sp
@account_name = 'DoNotReply',
@description = 'My Default Email',
@email_address = 'BODI@farmerbros.com',
@display_name = 'TaxReturn SQL2012Test',
@replyto_address = null,
@mailserver_name = 'FBCMAILHUB.FBCTORRANCE.COM',
@username = 'DoNotReply@farmerbros.com',
@port = 25, -- Check with your admin for correct port
@enable_ssl = False -- Enable ssl communication


-- update name
EXECUTE msdb.dbo.sysmail_Update_account_sp
@account_name = 'DoNotReply',
@description = 'My Default Email',
@email_address = 'BODI@farmerbros.com',
@display_name = 'TaxReturn SQL2012Test',
@replyto_address = null,
@mailserver_name = 'FBCMAILHUB.FBCTORRANCE.COM',
@username = 'DoNotReply@farmerbros.com',
@port = 25, -- Check with your admin for correct port
@enable_ssl = False -- Enable ssl communication



--6- Added account to the profile:
EXECUTE msdb.dbo.sysmail_add_profileaccount_sp
@profile_name = 'DoNotReply',
@account_name = 'DoNotReply',
@sequence_number = 1
GO 

7-Made sure the define port (25 in my case) is allowed in the server. 

8- Test :


EXECUTE msdb.dbo.sp_send_dbmail 
@profile_name='Farmer',
@recipients='ychoi@farmerbros.com',
@subject = 'Test e-mail sent from database mail',
@body = 'This is a test message sent from the newly created database mail account',
@reply_to = 'info@mydomain.com'
GO



EXECUTE msdb.dbo.sysmail_add_principalprofile_sp
@profile_name = 'Farmer',
@principal_name = 'public',
@is_default = 1 ; -- Make this the default profile
GO



EXECUTE msdb.dbo.sysmail_update_principalprofile_sp
@profile_name = 'Farmer',
@principal_name = 'public',
@is_default = 1 ; -- Make this the default profile
GO



SELECT is_broker_enabled FROM sys.databases WHERE name = 'msdb'


EXECUTE dbo.sysmail_help_status_sp;



sp_configure 'show advanced options', 1;
GO
RECONFIGURE;
GO
sp_configure 'Database Mail XPs', 1;
GO
RECONFIGURE
GO

use msdb;

EXECUTE dbo.sysmail_start_sp;


EXEC msdb.sys.sp_helprolemember 'DatabaseMailUserRole';


sp_addrolemember @rolename = 'DatabaseMailUserRole'
   ,@membername = 'sa';


   EXEC msdb.dbo.sysmail_help_principalprofile_sp;


   EXEC msdb.dbo.sysmail_help_status_sp;

   EXEC msdb.dbo.sysmail_start_sp;


   EXEC msdb.dbo.sysmail_help_queue_sp @queue_type = 'mail';